var a = require("../../../@babel/runtime/helpers/defineProperty"), t = getApp();

Page({
    data: {
        language: "",
        loading: !1,
        allLoaded: !1,
        goload: !0,
        isLoadMore: !0,
        page: 1,
        total_page: 0,
        cupconList: [],
        COUPON_URL: "plugin.hotel.frontend.hotel.couponList.index",
        GET_COUPIN: "plugin.hotel.frontend.hotel.couponGet.index",
        id: ""
    },
    onLoad: function(a) {
        a.id && this.setData({
            id: a.id
        }), this.initData(), this.getData();
    },
    onReady: function() {
        var a = wx.getStorageSync("langIndex");
        this.setData({
            language: a.en
        });
    },
    onShow: function() {},
    onHide: function() {},
    onUnload: function() {},
    onPullDownRefresh: function() {},
    onReachBottom: function() {
        this.data.isLoadMore ? this.getMoreData(this.data.page) : console.log("没有更多数据");
    },
    onShareAppMessage: function() {},
    initData: function() {
        this.setData({
            loading: !1,
            allLoaded: !1,
            goload: !0,
            isLoadMore: !0,
            page: 1,
            total_page: 0,
            cupconList: []
        });
    },
    getData: function() {
        var a = this, e = t.getNetAddresss(a.data.COUPON_URL);
        t._getNetWork({
            url: e,
            data: {
                hotel_id: this.data.id,
                page: this.data.page
            },
            success: function(t) {
                var e = t.data;
                1 == e.result && a.setData({
                    cupconList: e.data.data,
                    total_page: e.data.last_page
                });
            },
            fail: function(a) {
                console.log(a);
            }
        });
    },
    getMoreData: function() {
        var a = this, e = t.getNetAddresss(a.data.COUPON_URL);
        this.data.page != this.data.total_page && (this.data.page >= this.data.total_page ? this.setData({
            loading: !0,
            allLoaded: !0
        }) : (this.setData({
            page: this.data.page + 1
        }), t._getNetWork({
            url: e,
            data: {
                hotel_id: this.data.id,
                page: this.data.page
            },
            success: function(t) {
                var e = t.data;
                1 == e.result ? a.setData({
                    cupconList: a.data.cupconList.concat(e.data.data),
                    loading: !1,
                    allLoaded: !1
                }) : a.setData({
                    page: a.data.page - 1,
                    loading: !0,
                    allLoaded: !0,
                    isLoadMore: !1
                });
            },
            fail: function(a) {
                console.log(a);
            }
        })));
    },
    getCoupon: function(e) {
        var o = e.currentTarget.dataset.id, n = e.currentTarget.dataset.index, i = this, d = t.getNetAddresss(i.data.GET_COUPIN);
        t._getNetWork({
            url: d,
            data: {
                coupon_id: o
            },
            success: function(t) {
                var e = t.data;
                1 == e.result ? (i.setData(a({}, "cupconList[" + n + "]", e.data)), wx.showToast({
                    title: "领取成功",
                    icon: "none",
                    duration: 1500
                })) : wx.showToast({
                    title: e.msg,
                    icon: "none",
                    duration: 1500
                });
            },
            fail: function(a) {
                console.log(a);
            }
        });
    }
});